/**
 * 页面代码可以复用
 */
    /**
     * 移入移出
     * @param num
     */
    function chkIn(num)
    {
        $(".query"+num+"").addClass("active");
    }
    function chkOut(num)
    {
        $(".query"+num+"").removeClass("active");
    }
   /**
     * 共性代码-----使用模糊查询的调用
     * @param tishi
     * @param idSelector
     * @param result
     * @param currentValue
     * @param name
     * @param message
     */
    function fuzzyQuery(tishi,idSelector,result,currentValue,name,message) {
            var url="/ruoyi/personal/all/"+currentValue+"";
            currentValue=currentValue.replace(/\%/g,"%25");
            $.get(url,null,resultDisplay,"json");
            function resultDisplay(data) {
                if (data.length>0){
                    var $result = $("#"+result+"").empty();
                    for(var i=0;i<data.length;i++){
                        console.log(data[i].uName);
                        var reg=new RegExp("("+currentValue+")","g");
                        var str=data[i].uName;
                        var newste=str.replace(reg,"<font color='gray'>$1</font>")
                        var  $tr=$(" <div i=\"0\" class=\"qbsbox-suggestion qbsbox-suggestion-10001 query"+i+" \" onMouseOver=\"chkIn("+i+")\" onMouseOut=\"chkOut("+i+")\">\n" +
                            "                            <a href=\"javascript:void(0);\" onclick='stickyNote(\""+tishi+"\",\""+idSelector+"\",\""+data[i].uName+"\",\""+name+"\",\""+message+"\")' ><span class=\"qbsbox-s-text\">"+newste+"</span></a>\n" +
                            "                        </div>");
                        $result.append($tr)
                    }
                    $("#"+tishi+"").show();
                }
            }
    }

    /**
     * 点击模糊查询的结果将结果添加到
     * @param tishi
     * @param idSelector
     * @param result
     * @param name
     * @param message
     */
    function stickyNote(tishi,idSelector,result,name,message) {
        var lengli=$("#"+idSelector+" li").length;
        var $ul = $("#"+idSelector+"")
        if (lengli==0){
            var title = $("#"+idSelector+" li:eq("+i+")").attr("title");//123
            if (result!=title){
                var $li=$(" <li class=\"select2-selection__choice\" title=\""+result+"\">\n" +
                    ""+result+" <span class=\"select2-selection__choice__remove\" onclick='ces(\""+idSelector+"\",\""+result+"\",\""+message+"\")'>×</span>\n" +
                    "</li>");
                $ul.append($li);
            }
        }
        for (var i=0;i<lengli;i++){
            var title = $("#"+idSelector+" li:eq("+i+")").attr("title");//123
            if (result!=title){
                var $li=$(" <li class=\"select2-selection__choice result-li \" title=\""+result+"\">\n" +
                    ""+result+" <span class=\"select2-selection__choice__remove\" onclick='ces(\""+idSelector+"\",\""+result+"\",\""+message+"\")'>×</span>\n" +
                    "</li>");
                $ul.append($li);
                break;
            }else if(result==title){
                break;
            }
        }
        $("#"+tishi+"").hide();
        $("input[name='"+name+"']").val("");
        amend(idSelector,message);
    }

    /**
     * 移除带有某某字的节点
      * @param idSelector
     * @param contains
     * @param message
     */
    function ces(idSelector,contains,message) {
        $("#"+idSelector+" li").remove(":contains('"+contains+"')");
        amend(idSelector,message);
    }

    /**
     * 通过传入的id名称改变样式
     * @param idSelector
     * @param message
     */
    function amend(idSelector,message){
        var lengli=$("#"+idSelector+" li").length;
        if (lengli==0){
            $("#"+message+"").hide();
        }else {
            $("#"+message+"").show();
        }
    }